package com.liuqi.business.controller.front;

import com.liuqi.anno.user.CurUserId;
import com.liuqi.base.BaseFrontController;
import com.liuqi.business.service.*;
import com.liuqi.response.ReturnResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @author: Mr.Liu
 * @date: 2021/3/18 16:11
 * @version: 1.0
 * @class: MiningOrderController
 * @desc: 订单相关控制器
 */
@Api(description ="合约订单" )
@RestController
@RequestMapping(value = "/front/order")
public class MiningOrderController extends BaseFrontController {

    private final MiningOrderService miningOrderService;

    @Autowired
    private MiningConfigService miningConfigService;


    public MiningOrderController(MiningOrderService miningOrderService) {
        this.miningOrderService = miningOrderService;
    }

    @ApiOperation(value = "创建合约订单")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "long", name = "configId", value = "合约id", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "BigDecimal", name = "num", value = "数量", required = true, paramType = "query")
    })
    @PostMapping(value = "/createOrder")
    public ReturnResponse createOrder(@CurUserId long userId, long configId, BigDecimal num) {
        return miningOrderService.createOrder(userId,configId,num);
    }

    @ApiOperation(value = "消耗CRA币")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "long", name = "currencyId", value = "CRA币种id", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "BigDecimal", name = "num", value = "CRA币数量", required = true, paramType = "query")
    })
    @PostMapping(value = "/consumeCra")
    public ReturnResponse consumeCra(@CurUserId long userId,long currencyId,BigDecimal num){
        return miningOrderService.consumeCra(userId,currencyId,num);
    }

    @ApiOperation(value = "创建等级订单")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "long", name = "gradeId", value = "等级id", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "BigDecimal", name = "num", value = "数量", required = true, paramType = "query")
    })
    @PostMapping(value = "/createGradeOrder")
    public ReturnResponse createGradeOrder(@CurUserId long userId,long gradeId,BigDecimal num){
        return miningOrderService.createGradeOrder(userId,gradeId,num);
    }

}
